package com.lin.reggie.controller;

import com.lin.reggie.common.R;
import com.lin.reggie.entity.OrderDetail;
import com.lin.reggie.entity.Orders;
import com.lin.reggie.entity.Page;
import com.lin.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired(required = false)
    private OrderService orderService;



    @GetMapping("/userPage")
    public R<Page<OrderDetail>> find(Integer page, Integer pageSize, HttpSession session){
        Long userId = (Long) session.getAttribute("user");
        Page<OrderDetail> orderDetailPage = orderService.find(page, pageSize, userId);
          return R.success(orderDetailPage);
    }

    @RequestMapping("/submit")
    public R<String>sumbit(@RequestBody Orders orders, HttpSession session){

        Long id = (Long) session.getAttribute("user");
        orderService.addOrder(orders,id);
        return R.success("购买成功");
    }
}
